<?php

	if($_POST)
	{
		if(!trim($_POST['faceimg'])&&$_FILES['photo']['name'])
		{
			$upimg = $_->images->upLoad('photo',array('width'=>520,'height'=>250));
			$_POST['faceimg'] = 'http://pic.dev'.substr($upimg,12);
		}

		$data = array(
			'title' => $_POST['title'],
			'description' => $_POST['descrption'],
			'cates' => $_POST['cates'],
			'catename' => $_POST['sele-text'],
			'faceimg' => $_POST['faceimg'],
			'tage' => $_POST['tage']?implode(',',$_POST['tage']):'',
			'content' => $_POST['content'],
			'author'=>$_POST['author']?$_POST['author']:'37.5°',
			'addtime' =>time(),
		);

		if($_POST['id'])
		{
			if($_->articles->_update($data,array('id'=>$_POST['id'])))
			{
				header('location:/admins/manage_articles.php');exit;
			}
		}elseif($_->articles->_insert($data))
		{
			header('location:?res=1');exit;
		}
	}
	if($id=intval($_GET['id']))
	{
		$article = $_->articles->_select('',array('id'=>$id));
		$article = $article[0];
	}
	$article['tage'] = explode(',',$article['tage']);
	$catename = $_->cates->_select(array('id as cates','catename'),array('type'=>1,'status'=>1));
	$notice = $_GET['res']==1?'1':'0';
	$tages = array('php'=>'php','js'=>'js','css'=>'css','other'=>'其他');
	$smarty->_assign(array('notice','catename','article','tages'));
	$smarty->_display();
?>